import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @program: JavaWeb
 * @description
 * @author: taoli
 * @create: 2020-12-10 11:27
 **/
public class CheckCode {
    public static void getimage(OutputStream outputStream) throws IOException {
        // 实现类 带缓冲区图像类
        BufferedImage image = new BufferedImage(60, 32, BufferedImage.TYPE_BYTE_BINARY);
        // 绘图
        Graphics g = image.getGraphics();
        // 将此图形上下文的当前颜色设置为指定的颜色。
        g.setColor(Color.WHITE);

        g.drawString(CheckCode.getext(), 8, 24);

        ImageIO.write(image, "png", outputStream);


    }
    public static String getext() {
        String text = "";
        int a = 4;
        for (int i = 0; i < a; i++) {
            /**
             * 返回介于 0（包含） ~ 1（不包含） 之间的一个随机数
             * [0 10)
             */
            text += (int) (Math.random() * 10);
        }
        return text;

    }
}
